"""
pip install fake_useragent
随机生成UserAgent
from fake_useragent import UserAgent

ua = UserAgent()
print(ua.random)
"""

"""
封装函数实现日期的格式的转化是日期的减少
from datetime import datetime, timedelta


def reduce_days_and_format(date_string):
    # 定义日期格式
    date_format = "%Y%m%d"

    # 将输入的字符串转换为日期对象
    try:
        date = datetime.strptime(date_string, date_format)
    except ValueError:
        raise ValueError("Invalid date format. Please use YYYYMMDD.")

    # 减少7天
    new_date = date - timedelta(days=7)

    # 格式化为 YYYYMMDD
    return new_date.strftime(date_format)
# 示例使用
result = reduce_days_and_format("20241104")
print(result)  # 输出: 20241028
"""